package com.xiang;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JsonMatcher {
    private static final String JSON_PATTERN = "\\{\"head\":\\{.*?\\}\\}";

    public static void main(String[] args) throws IOException {
//        String input = "";
        String fileName = "D:\\projects\\java\\demo-utils\\xiang-filter\\2.txt";
        String input = new String(Files.readAllBytes(Paths.get(fileName)));

        Pattern pattern = Pattern.compile(JSON_PATTERN);
        Matcher matcher = pattern.matcher(input);
        JSONArray array =new JSONArray();
        while (matcher.find()) {
            String json = matcher.group();
            JSONObject jsonObject = JSONObject.parseObject(json);
//            array.add(jsonObject);
            System.out.println(json);
            System.out.println();
            System.out.println(jsonObject);
        }
        System.out.println(array);
    }
}
